<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/5 0005
 * Time: 下午 7:25
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller
{
    public $comment_path;   //公共的目录路径
    /**
     * 初始化
     * */
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->helper('url');
        $this->comment_path = 'application/views/home/';
    }
    /**
     * 前台首页
     *
     * */
    public function index($page='index')
    {
        //判断页面是否存在
        if(!file_exists($this->comment_path.$page.'.php'))
        {
            //页面不存在
            show_404();
        }
        $this->load->model('House_model');
        $data['house']=$this->House_model->faceData();
        //var_dump($data);die;
        $this->load->model('Area_model');
        //获取省
        $data['province'] = $this->Area_model->getProvince($parentid=0);
        //ajax传值获取城市,县区
        if ($_GET && count($_GET)>0) {
            $type = $_GET['type'];
            switch ($type) {
                case 'city' :
                    $id = $_GET['id'];
                    $city = $this->Area_model->getProvince($parentid = $id);
                    //获取组装数据
                    $city_data = $this->Area_model->checkData($city);
                    $ret = ['status' => 'success', 'message' => $city_data];
                    echo json_encode($ret);
                    die;
                    break;

                case 'country':
                    $id = $_GET['id'];
                    $country = $this->Area_model->getProvince($parentid = $id);
                    //获取组装数据
                    $country_data = $this->Area_model->checkData($country);
                    //print_r($country_data);die;
                    $ret = ['status' => 'success', 'message' => $country_data];
                    echo json_encode($ret);
                    die;
                    break;
            }

        }

        //页面标题
        $data['title']='首页';
        //渲染页面
        $this->load->view('home/header',$data);   //公共的头部
        $this->load->view('home/'.$page,$data);  //主体内容
        $this->load->view('home/footer',$data);  //尾部
    }

}